<?php

use Drupal\wx_transfers\Entity\WxTransfers;

function wx_transfers_wx_transfers_entity_form($form, &$form_state, WxTransfers $e, $op) {
  $form_state['build_info']['files']['form'] = drupal_get_path('module', 'wx_transfers') . '/wx_transfers.forms.inc';
  $form_state[WxTransfers::class] = $e;

  field_attach_form($e->entityType(), $e, $form, $form_state);

  $form['actions'] = ['#type' => 'actions'];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => t('保存'),
  ];
  return $form;
}

function wx_transfers_wx_transfers_entity_form_submit($form, &$form_state) {
  $e = $form_state[WxTransfers::class];
  if ($e instanceof WxTransfers) {
    entity_form_submit_build_entity($e->entityType(), $e, $form, $form_state);
    $e->save();
  }
}

function wx_transfers_wx_transfers_delete_form($form, &$form_state, WxTransfers $e) {
  $form_state['build_info']['files']['form'] = drupal_get_path('module', 'wx_transfers') . '/wx_transfers.forms.inc';
  $form_state[WxTransfers::class] = $e;
  return confirm_form($form,
    t('Are you sure you want to delete %title?', ['%title' => $e->label()]),
    'admin/content/wx_transfers/' . $e->id,
    t('This action cannot be undone.'),
    t('Delete'),
    t('Cancel')
  );
}

function wx_transfers_wx_transfers_delete_form_submit($form, &$form_state) {
  $e = $form_state[WxTransfers::class];
  if ($e instanceof WxTransfers) {
    $e->delete();
  }
}

